//
//  ACCacheViewController.m
//  LFUCache_Example
//
//  Created by autohome on 2021/8/18.
//  Copyright © 2021 caixiang305621856. All rights reserved.
//

#import "ACCacheViewController.h"
#import "ACCache.h"

@interface Test1 : NSObject
@property (copy, nonatomic) NSString *name;
@end

@implementation Test1
@end

@interface Test2 : NSObject
@property (assign, nonatomic) NSInteger age;
@end

@implementation Test2
@end



@interface ACCacheViewController ()

@end

@implementation ACCacheViewController{
    ACCache *_cache;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"ACCache Test";
    
    ACCacheConfiguration *config = [ACCacheConfiguration defaultCacheConfig];
    //配置插件名
    config.pluginName = @"ArticlePlugin";
    //配置缓存名
    config.name = @"ACCache";
    //配置磁盘缓存失效时长 单位s
    config.effectiveCacheTime = 10;
    //配置是否需要进入后台清空内存缓存
    config.shouldRemoveAllObjectsWhenEnteringBackground = NO;
    //初始化缓存对象
   _cache = [ACCache cacheWithConfiguration:config];
    
    //缓存10000条常规数据
    for (NSInteger i = 0; i < 10000; i ++) {
        [_cache setObject:[NSString stringWithFormat:@"value-%zd",i] forKey:[NSString stringWithFormat:@"key-%zd",i]];
    }
    //获取key-5 的 缓存值
    [_cache objectForKey:@"key-5"];
    
    //缓存两个参数的并写入磁盘
    [_cache setObject:@"t1" vaule:@"t2" forKey:@"t1_t2" toDisk:YES];
    NSDictionary *dict =  [_cache objectForKey:@"t1_t2"];
    NSLog(@"dict - %@",dict);
    
    
    
    //获取数据 未缓存DB前
//    NSString *value =  [_cache objectForKey:@"---------------key---------5"];
//    NSString *value1 =  [_cache.memoryCache objectForKey:@"---------------key---------5"];
//    NSString *value2 =  [_cache.diskCache objectForKey:@"---------------key---------5"];

//    NSLog(@"%@-%@-%@",value,value1,value2);
    [self loadCustomModelDatas];
}

- (void)loadCustomModelDatas {
//    Test1 *t1 = [Test1 new];
//    t1.name = @"test1";
//
//    Test2 *t2 = [Test2 new];
//    t2.age = 10;
    
    [_cache setObject:@"t1" vaule:@"t2" forKey:@"t1_t2" toDisk:YES];
    NSDictionary *dict =  [_cache objectForKey:@"t1_t2"];
    NSLog(@"dict - %@",dict);
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
